Skip to content

Conversation

@joyewon0705
Copy link
Collaborator

📌 개요

  • 애플리케이션 실행 시 중복 매핑에 의한 제약 조건 위반 해결
  • 기존 DevInitData 클래스에 포함되어 있던 데이터 초기화 로직을 DevInitService로 분리

🔨 작업 내용

1. DevInitData 구조 개선

  • ApplicationRunner에서 data.sql 실행 여부만 판단하도록 단순화
  • 실제 초기 데이터 생성 로직은 DevInitService로 위임
  • DevInitData 내 불필요한 repository 및 passwordEncoder 의존성 제거

2. DevInitService 신규 생성

  • @Service 클래스 생성, 트랜잭션 관리 및 데이터 초기화 담당
  • 유저, 게시글, 댓글, 카테고리 데이터 초기화 로직을 명확히 분리
  • 게시글과 카테고리 매핑 시 EntityManager.flush() 추가로 중복 insert 방지

3. 제약 조건 위반(DataIntegrityViolationException) 해결

  • 기존 Post.updateCategories() 호출 시
    clear() 후 DELETE가 flush 되기 전에 INSERT가 수행되어 UNIQUE 제약 위반 발생
  • entityManager.flush() 추가하여 DELETE를 즉시 반영하도록 수정

4. PostCategory 초기화 누락 방지

  • postCategoryMappings 필드를 명시적으로 new ArrayList<>()로 초기화

🔗 관련 이슈

Closes #{이슈 번호}

📝 참고 사항

✅ 체크리스트

  • 기능 동작 확인
  • 테스트 코드 작성
  • 문서/주석 추가 및 최신화

@github-actions github-actions bot changed the title Refactor: DevInitData 구조 분리 및 초기화 로직 개선 Refactor: DevInitData 구조 분리 및 초기화 로직 개선 (#212) Oct 11, 2025
@joyewon0705 joyewon0705 merged commit 69ed889 into dev Oct 12, 2025
3 checks passed
@github-actions github-actions bot deleted the Refactor/212 branch October 12, 2025 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants